﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class PostingDetails : System.Web.UI.Page
{
    PostingDAO postDAO = new PostingDAO();
    SaleDAO saleDAO = new SaleDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
     //   int exhibitionId = int.Parse(Request["ExhibitionID"]);
        Int64 postID = Int64.Parse(Request["PostingID"]);
        DataSet ds = postDAO.GetPostingByPostingID(postID);
        if (ds.Tables.Count > 0)
        {
            dtlPostingDetails.DataSource = ds;
            dtlPostingDetails.DataBind();
        }

        foreach (DataListItem item in dtlPostingDetails.Items)
        {
            if (dtlPostingDetails.Items.Count > 0)
            {
                DataList dl = (DataList)item.FindControl("dtlSaleDetails");
                dl.DataSource = saleDAO.SelectSaleInfo(postID);
                dl.DataBind();
            }
        }
        PostingExhibitionDAO postExhiDAO = new PostingExhibitionDAO();
         string _status = postExhiDAO.GetStatusById(postID);
         if (_status == "Sold")
         {
             btnBuy.Visible = false;
         }
    }

    public string IsPayed(string obj)
    {
        string result = "Not yet";
        bool payed;
        if (obj != null || !obj.Equals(""))
        {
            if (obj == "True")
                payed = true;
            else payed = false;

            if (payed == true)
                result = "Paid";
        }
        return result;
    }

    protected void btnBuy_Click1(object sender, ImageClickEventArgs e)
    {
        Basket.Instance.AddItem(Int64.Parse(Request.QueryString["PostingID"]));
        
        if (Session["roleID"]!=null)
        {
            if (Session["roleID"].ToString().Equals("5"))
            {
                Response.Redirect("~/Admin/ShoppingCart.aspx");
            }                     
        }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Your must Login with Customer Account!');", true);
            
        
    }
}